﻿

namespace Mulala.Cavan.Domain.MainBoundedContext.MulalaModule
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Mulala.Cavan.Core.Persistent;
    using Mulala.Cavan.Domain.MainBoundedContext.ConsignModule;
    using Mulala.Cavan.Domain.MainBoundedContext.SearchModule;
    using Mulala.Cavan.Core.MyLinq;
    using Mulala.Cavan.Core.Extension;

    public class ConsignBidderSpecification : ISpecification<ConsignBidder, ConsignBidderSearch>
    {
        #region ISpecification<ConsignBidder,ConsignBidderSearch> Members

        public ConsignBidderSearch SearchParams
        {
            get;
            set;
        }

        #endregion

        #region ISpecification<ConsignBidder> Members

        public System.Linq.Expressions.Expression<Func<ConsignBidder, bool>> Expression
        {
            get
            {
                IQueryBuilder<ConsignBidder> queryBuilder = QueryBuilder.Create<ConsignBidder>();

                if (null != SearchParams)
                {
                    if (SearchParams.BidderID > 0)
                    {
                        queryBuilder = queryBuilder.Equals(cb => cb.Bidder.ID, SearchParams.BidderID);
                    }
                    if (SearchParams.BidderCorporationID > 0)
                    {
                        queryBuilder = queryBuilder.Equals(cb => cb.BidderCorporation.ID, SearchParams.BidderCorporationID);
                    }
                    if (SearchParams.ProprietorID > 0)
                    {
                        queryBuilder = queryBuilder.Equals(cb => cb.Consign.Proprietor.ID, SearchParams.ProprietorID);
                    }
                }

                return queryBuilder.Expression.Expand();
            }
        }

        #endregion
    }
}
